package com.anda.logistics.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.anda.logistics.model.DriverLocation;
import com.anda.logistics.model.DriverLocationRt;
import com.anda.logistics.model.FreightDeliver;
import com.anda.logistics.model.FreightSource;
import com.anda.logistics.model.SystemCode;
import com.anda.logistics.model.TruckInfo;
import com.anda.logistics.service.DriverLocationService;
import com.anda.logistics.service.FreightDeliverService;
import com.anda.logistics.service.FreightSourceService;
import com.anda.logistics.service.SystemCodeService;
import com.anda.logistics.service.TruckInfoService;

public class LocationAction extends AndaBaseAction {
	private static final long serialVersionUID = -1099725774354462203L;
	private String mobileNo;
	private TruckInfoService truckInfoService;
	private DriverLocationService driverLocationService;
	private SystemCodeService systemCodeService;
	private FreightDeliverService freightDeliverService;
	private FreightSourceService freightSourceService;
	private TruckInfo truckInfo;
	private DriverLocationRt driverLocation;
	private FreightDeliver freightDeliver;
	private FreightSource freightSource;
	private Map<String,List<SystemCode>> mapCode;
	
	@Action(value="/manager/location/query"
			,results=@Result(location="query.jsp",name="success")
		)
	public String execute(){
		return SUCCESS;
	}
	
	@Action(value="/manager/location/search"
		,results=@Result(location="query.jsp",name="success")
	)
	public String search(){
		truckInfo = truckInfoService.getOneByMobileNo(mobileNo);
		if (truckInfo !=null) {
			if ( truckInfo.getTruckState() == 2) {
				freightDeliver = freightDeliverService.getOnRoadOneByTruckId(truckInfo.getId());
				if (freightDeliver != null){
					freightSource = freightSourceService.getOneById(freightDeliver.getFreightId());
				}
			}
			driverLocation = driverLocationService.getLocationByMobileNo(mobileNo);
			mapCode = this.systemCodeService.getAllPartedCode();
		}
		System.out.println(mobileNo);
		System.out.println(truckInfo);
		return SUCCESS;
	}

	public String getMobileNo() {
		return mobileNo;
	}

	public void setMobileNo(String mobileNo) {
		this.mobileNo = mobileNo;
	}

	public TruckInfoService getTruckInfoService() {
		return truckInfoService;
	}
	@Resource
	public void setTruckInfoService(TruckInfoService truckInfoService) {
		this.truckInfoService = truckInfoService;
	}
	

	public DriverLocationService getDriverLocationService() {
		return driverLocationService;
	}
	@Resource
	public void setDriverLocationService(DriverLocationService driverLocationService) {
		this.driverLocationService = driverLocationService;
	}
	
	

	public FreightSourceService getFreightSourceService() {
		return freightSourceService;
	}
	@Resource
	public void setFreightSourceService(FreightSourceService freightSourceService) {
		this.freightSourceService = freightSourceService;
	}

	public FreightDeliverService getFreightDeliverService() {
		return freightDeliverService;
	}
	@Resource
	public void setFreightDeliverService(FreightDeliverService freightDeliverService) {
		this.freightDeliverService = freightDeliverService;
	}

	public SystemCodeService getSystemCodeService() {
		return systemCodeService;
	}
	@Resource
	public void setSystemCodeService(SystemCodeService systemCodeService) {
		this.systemCodeService = systemCodeService;
	}

	public TruckInfo getTruckInfo() {
		return truckInfo;
	}

	public void setTruckInfo(TruckInfo truckInfo) {
		this.truckInfo = truckInfo;
	}

	public DriverLocationRt getDriverLocation() {
		return driverLocation;
	}

	public void setDriverLocation(DriverLocationRt driverLocation) {
		this.driverLocation = driverLocation;
	}	
	
	public FreightDeliver getFreightDeliver() {
		return freightDeliver;
	}

	public void setFreightDeliver(FreightDeliver freightDeliver) {
		this.freightDeliver = freightDeliver;
	}

	public FreightSource getFreightSource() {
		return freightSource;
	}

	public void setFreightSource(FreightSource freightSource) {
		this.freightSource = freightSource;
	}

	public Map<String, List<SystemCode>> getMapCode() {
		return mapCode;
	}
	public void setMapCode(Map<String, List<SystemCode>> mapCode) {
		this.mapCode = mapCode;
	}
	
	public String getMapTruckType(){
		return systemCodeService.getMapCode(mapCode,"trucktype");
	}
	
	public String getMapBodyStruc(){
		return systemCodeService.getMapCode(mapCode,"bodystruc");
	}
	public String getMapSex(){
		return systemCodeService.getMapCode(mapCode,"sex");
	}
	public String getMapLicenseType(){
		return systemCodeService.getMapCode(mapCode,"licensetype");
	}
	public String getMapCapacity(){
		return systemCodeService.getMapCode(mapCode,"capacity");
	}
	public String getMapTruckLength(){
		return systemCodeService.getMapCode(mapCode,"trucklength");
	}
	public String getMapTruckState(){
		return systemCodeService.getMapCode(mapCode, "truckstate");
	}
}
